.class public Lcom/philzhu/www/framework/impl/AndroidAudio;
.super Ljava/lang/Object;
.source "AndroidAudio.java"

# interfaces
.implements Lcom/philzhu/www/framework/Audio;


# instance fields
.field assets:Landroid/content/res/AssetManager;

.field soundPool:Landroid/media/SoundPool;


# direct methods
.method public constructor <init>(Landroid/app/Activity;)V
    .locals 4
    .parameter "activity"

    .prologue
    const/4 v3, 0x3

    .line 19
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 20
    invoke-virtual {p1, v3}, Landroid/app/Activity;->setVolumeControlStream(I)V

    .line 21
    invoke-virtual {p1}, Landroid/app/Activity;->getAssets()Landroid/content/res/AssetManager;

    move-result-object v0

    iput-object v0, p0, Lcom/philzhu/www/framework/impl/AndroidAudio;->assets:Landroid/content/res/AssetManager;

    .line 22
    new-instance v0, Landroid/media/SoundPool;

    const/16 v1, 0x14

    const/4 v2, 0x0

    invoke-direct {v0, v1, v3, v2}, Landroid/media/SoundPool;-><init>(III)V

    iput-object v0, p0, Lcom/philzhu/www/framework/impl/AndroidAudio;->soundPool:Landroid/media/SoundPool;

    .line 23
    return-void
.end method


# virtual methods
.method public newMusic(Ljava/lang/String;)Lcom/philzhu/www/framework/Music;
    .locals 5
    .parameter "filename"

    .prologue
    .line 28
    :try_start_0
    iget-object v2, p0, Lcom/philzhu/www/framework/impl/AndroidAudio;->assets:Landroid/content/res/AssetManager;

    invoke-virtual {v2, p1}, Landroid/content/res/AssetManager;->openFd(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;

    move-result-object v0

    .line 29
    .local v0, assetDescriptor:Landroid/content/res/AssetFileDescriptor;
    new-instance v2, Lcom/philzhu/www/framework/impl/AndroidMusic;

    invoke-direct {v2, v0}, Lcom/philzhu/www/framework/impl/AndroidMusic;-><init>(Landroid/content/res/AssetFileDescriptor;)V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    return-object v2

    .line 30
    .end local v0           #assetDescriptor:Landroid/content/res/AssetFileDescriptor;
    :catch_0
    move-exception v2

    move-object v1, v2

    .line 31
    .local v1, e:Ljava/io/IOException;
    new-instance v2, Ljava/lang/RuntimeException;

    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "Couldn\'t load music \'"

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v3, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    const-string v4, "\'"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v2
.end method

.method public newSound(Ljava/lang/String;)Lcom/philzhu/www/framework/Sound;
    .locals 6
    .parameter "filename"

    .prologue
    .line 38
    :try_start_0
    iget-object v3, p0, Lcom/philzhu/www/framework/impl/AndroidAudio;->assets:Landroid/content/res/AssetManager;

    invoke-virtual {v3, p1}, Landroid/content/res/AssetManager;->openFd(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;

    move-result-object v0

    .line 39
    .local v0, assetDescriptor:Landroid/content/res/AssetFileDescriptor;
    iget-object v3, p0, Lcom/philzhu/www/framework/impl/AndroidAudio;->soundPool:Landroid/media/SoundPool;

    const/4 v4, 0x0

    invoke-virtual {v3, v0, v4}, Landroid/media/SoundPool;->load(Landroid/content/res/AssetFileDescriptor;I)I

    move-result v2

    .line 40
    .local v2, soundId:I
    new-instance v3, Lcom/philzhu/www/framework/impl/AndroidSound;

    iget-object v4, p0, Lcom/philzhu/www/framework/impl/AndroidAudio;->soundPool:Landroid/media/SoundPool;

    invoke-direct {v3, v4, v2}, Lcom/philzhu/www/framework/impl/AndroidSound;-><init>(Landroid/media/SoundPool;I)V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    return-object v3

    .line 41
    .end local v0           #assetDescriptor:Landroid/content/res/AssetFileDescriptor;
    .end local v2           #soundId:I
    :catch_0
    move-exception v3

    move-object v1, v3

    .line 42
    .local v1, e:Ljava/io/IOException;
    new-instance v3, Ljava/lang/RuntimeException;

    new-instance v4, Ljava/lang/StringBuilder;

    const-string v5, "Couldn\'t load sound \'"

    invoke-direct {v4, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v4, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    const-string v5, "\'"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v3
.end method
